import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
public class Logger {
    static final String LOG_FILE = "log.txt";

    static synchronized void log(String operator, String action) {
        String ts = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        String line = ts + " | " + operator + " | " + action;
        try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(LOG_FILE, true)))) {
            out.println(line);
        } catch (IOException e) {
            System.err.println("日志写入失败: " + e.getMessage());
        }
    }
}
